PageView

  • Usage

    The PageView widget in Flutter is used to create a scrollable list of pages that users can swipe through horizontally. It's commonly used to create wizards, image galleries, or any kind of horizontal swiping interface.

    
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      final List<Color> colors = [Colors.blue, Colors.green, Colors.red, Colors.yellow];
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text('PageView Example'),
            ),
            body: PageView.builder(
              itemCount: colors.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  color: colors[index],
                  child: Center(
                    child: Text(
                      'Page ${index + 1}',
                      style: TextStyle(color: Colors.white, fontSize: 20.0),
                    ),
                  ),
                );
              },
            ),
          ),
        );
      }
    }
    
    

    In this example:

    PageView.builder creates a scrollable list of pages based on the provided itemBuilder function.
    itemCount specifies the number of pages in the PageView.
    Each page is represented by a Container with a background color from the colors list, containing a centered Text widget displaying the page number.